package com.handtransaction.controller;

import com.handtransaction.entity.User;
import com.handtransaction.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 管理员对用户的管理
 */
@Controller
public class AdminToUserController {
    @Autowired
    UserService userService;

    //查看平台的所有用户
    @RequestMapping("/readAllUser")
    public String readAllUser(Model model){
        List<User> userList = userService.readAllUser();
        model.addAttribute("userList",userList);
        return "admin/user/adminAllUser";
    }

    //进入用户主页

    //冻结用户权限 -- 用户无法登录
    @RequestMapping("/frozenUser")
    public String frozenUser(Integer uid,Integer upid){
        userService.isfrozenUser(uid,upid);
        return "redirect:/readAllUser";
    }

    //删除用户 -- 业务要求：只能删除被冻结的用户
    @RequestMapping("/deleteUserByAdmin")
    public String deleteUserByAdmin(Integer uid , Model model){
        model.addAttribute("isDelete" , userService.deleteUserByAdmin(uid));
        return "forward:/readAllUser";
    }





}
